#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os 
import re
import numpy as np

class StatData:
    def __init__(self):
        self.max = None
        self.min = None
        self.avg = None 

def mean(numbers):
    return np.mean(numbers)


def parsefile(filename):
    cpulist=[]
    file = open(filename, "r")
    lines = file.readlines()
    file.close()
    
    # 对每行进行分割
    for line in lines:
        # 根据空格或制表符等作为分隔符进行切割 python 使用一个或多个空格分割字符串
        words = line.split()
        # words = re.split(r'\s+', line)
        # words = re.findall(r'\w+', line)
        # 输出结果
        # print(split_line) 
        print(words)
        cpulist.append(float(words[8]))
    return cpulist


if __name__== "__main__" :
    cpulist=parsefile("data/new.txt")
    print(cpulist)
    stat=StatData()
    stat.max=max(cpulist)
    stat.min=min(cpulist)
    stat.avg=mean(cpulist)
    print('max={}, min={}, avg={}'.format(stat.max,stat.min,stat.avg) )
    


